﻿using System.Collections.Generic;
using System.Data;

using SiteUnity.Layers.Entity.General;
using SiteUnity.Frame.Common.Tools.Class;
using SiteUnity.Layers.Entity.PageItems.Rates;

namespace SiteUnity.Layers.Core.Provider.PageItems
{
    public class RateProvider : Provider
    {
        public RateProvider()
        {
            SetDefaultConnection();
        }
        public decimal selectRateAvarageByPage(Page page)
        {
            Database.clear();
            Database.addParameter("@page_guid", page.Guid);

            DataTable datatable = Database.executeQuery("SU_selectRateAvarageByPage");
            Database.close();

            if (!string.IsNullOrEmpty(((DataRow)datatable.Rows[0])[0].ToString()))
                return (decimal)((DataRow)datatable.Rows[0])[0];
            else
                return -1;
        }

        public void insertRate(Page page, Rate rate)
        {
            Database.clear();
            Database.addParameter("@pageGuid", page.Guid);
            Database.addParameter("@value", rate.Value);
            Database.addParameter("@ip", rate.IP);
            Database.addParameter("@typeID", rate.TypeID);
 
            Database.executeNonQuery("SU_insertRate");
            Database.close();
        }
    }
}
